package com.skb.task.controller;

import com.skb.task.pojo.Task;
import com.skb.task.service.TaskService;
import com.skb.task.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 沈楷博
 * @Company 永遠快樂
 * @Description
 * @Time 2024/9/10 下午4:36
 */
@RestController
@CrossOrigin(origins = "http://localhost:5173")
@RequestMapping("/task")
public class TaskController {
    @Autowired
    private TaskService taskService;

    /**
     * 通过projectId和parentId查询任务列表
     * @param projectId
     * @param parentId 0 说明是查询一级任务
     * @return
     */
    @GetMapping("/list")
    public QdResult list(Task task, String projectId, Long parentId){
        System.out.println(projectId);
        System.out.println(parentId);
        return taskService.list(task,projectId,parentId);
    }

    @PostMapping("/save")
    public QdResult save(@RequestBody Task task){
        return taskService.save(task);
    }

    @GetMapping("/get")
    public QdResult get(Long taskId){
        return taskService.queryById(taskId);
    }

    @PutMapping("/update")
    public QdResult update(@RequestBody Task task){
        return taskService.update(task);
    }

    @PostMapping("/delete")
    public QdResult deleteTask(@RequestBody Task task) {
        return taskService.deleteTask(task);
    }

    @PostMapping("/deletes")
    public QdResult deletesTask(@RequestBody String[] taskIds){
        return taskService.deletesTask(taskIds);
    }
}